﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Wallpaper.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddUserIPAndLastLoginTime : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            // 添加IP地址字段
            migrationBuilder.AddColumn<string>(
                name: "IPAddress",
                table: "users",
                type: "nvarchar(45)",
                maxLength: 45,
                nullable: true,
                defaultValue: null,
                comment: "用户IP地址");

            // 添加最后登录时间字段
            migrationBuilder.AddColumn<DateTime>(
                name: "LastLoginTime",
                table: "users",
                type: "datetime2",
                nullable: true,
                defaultValue: null,
                comment: "最后登录时间");

            // 创建最后登录时间索引
            migrationBuilder.CreateIndex(
                name: "idx_users_lastlogintime",
                table: "users",
                column: "LastLoginTime");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            // 删除索引
            migrationBuilder.DropIndex(
                name: "idx_users_lastlogintime",
                table: "users");

            // 删除最后登录时间字段
            migrationBuilder.DropColumn(
                name: "LastLoginTime",
                table: "users");

            // 删除IP地址字段
            migrationBuilder.DropColumn(
                name: "IPAddress",
                table: "users");
        }
    }
}
